package com.third.clock.ui.model.presenter;

import android.content.Context;
import android.text.TextUtils;

import com.third.clock.bean.LoginEntity;
import com.third.clock.bean.ResponseData;
import com.third.clock.manager.ClockManager;
import com.third.clock.manager.OkHttpClientManager;
import com.third.clock.ui.model.ILeaveActivityView;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/8/8 0008.
 */

public class LeaveActivityPresenter {

    public Context mContext;

    public ILeaveActivityView mView;

    public LeaveActivityPresenter(Context context){
        this.mContext=context;
    }

    public void setView(ILeaveActivityView view){
        this.mView=view;
    }

    public void postLeave(String type,long starttime,long endtime,String edittext){
        ClockManager clockManager=ClockManager.getInstace(mContext);
        if(clockManager!=null){
            OkHttpClientManager okHttpClientManager=clockManager.getOkHttpClientManager();
            if(okHttpClientManager!=null){
               if(starttime==0){
                   if(mView!=null) mView.onFail("开始时间请选择");
                   return;
               }
                if(endtime==0){
                    if(mView!=null) mView.onFail("结束时间请选择");
                    return;
                }
                if(starttime>endtime){
                    if(mView!=null) mView.onFail("结束时间必须大于开始之间");
                    return;
                }
                if(TextUtils.isEmpty(edittext)){
                    if(mView!=null) mView.onFail("请假事由不能为空");
                    return;
                }

                ResponseData<LoginEntity> responseData=clockManager.mLoginResponseData;
                if(responseData!=null&&responseData.getData()!=null){
                    Map<String,Object> leaveMap=new HashMap<>();
                    leaveMap.put("userid",responseData.getData().getUser_id());
                    leaveMap.put("name",responseData.getData().getName());

                }


            }
        }
    }


}
